#include "stdio.h"
main(){
	int i,f,m,n;
	char yn[10000],c,d;
	scanf("%d",&n);
	c=getchar();
	for(i=0;i<n;i++){
		f=m=0;
		while((c=getchar())!='\n'){
			if(c=='F'||c=='M'){
				if(c=='F')f++;else m++;
				if(getchar()=='F')f++;else m++;
			}
		}
		if(f==m)yn[i]='y';
		else yn[i]='n';
	}
	for(i=0;i<n;i++){
		if(yn[i]=='y')
			printf("LOOP\n");
		else if(yn[i]=='n') 
			printf("NO LOOP\n");
	}
}